<template>
	<s-layout title="包裹信息" class="package-wrap">
		<view class="container">
			<view class="card my-3 p-4 type-box">
				<view class="title mb-4">
					物品类型<text class="red">(必填)</text>
				</view>
				<view class="list">
					<view v-for="(item, index) in list" :key="index" class="item" :class="{ active: active == index }" @tap="onClick(index)">{{ item }}</view>
				</view>
				<view class="current">
					<input v-model="packageInfo.itemName" type="text" placeholder="可输入物品类型">
				</view>
				<view class="red">
					注意：请勿寄递国家机关公文
				</view>
			</view>
			<view class="card my-3 p-4 measure-box">
				<view class="ss-flex ss-row-between mb-4">
					<view class="title">
						预估重量(kg)<text class="red">(必填)</text>
					</view>
					<uni-number-box v-model="packageInfo.weight" @change="onChange" />
				</view>
				<view class="red mb-5">
					注意：默认重量为1KG，可更改，实际重量以收件员确认为准，超出重量快件，需要补差价
				</view>
				<view class="title mb-4">
					货物尺寸(cm)<text class="red">(非必填)</text>
				</view>
				<view class="ss-flex size">
					<view class="label">
						长
					</view>
					<input type="number" v-model="packageInfo.vloumLong">
					<view class="label">
						宽
					</view>
					<input type="number" v-model="packageInfo.vloumWidth">
					<view class="label">
						高
					</view>
					<input type="number" v-model="packageInfo.vloumHeight">
				</view>
			</view>
			<view class="card my-3 p-4 tip-box">
				重要提示：<br/>17:30快递员就已经下班了，第二天才会取
			</view>
			<view class="card my-3 p-4">
				<view class="title mb-4">
					备注
				</view>
				<textarea class="textarea" placeholder="给快递小哥捎句话（不超过20字）" v-model="packageInfo.billRemark"></textarea>
			</view>
		</view>
		<view class="fixed">
			<button class="button" @tap="onConfirm">
				确定
			</button>
		</view>
	</s-layout>
</template>

<script setup>
	import { ref, toRefs } from 'vue'
	import sheep from '@/sheep';
  import { onShow } from '@dcloudio/uni-app';
	
	const store = sheep.$store('mail')

	const packageInfo = ref({
		itemName: '日用品',
		weight: 1,
		vloumLong: 1,
		vloumWidth: 1,
		vloumHeight: 1,
		billRemark: ''
	})
	const list = [
		'文件',
		'数码电器',
		'衣物首饰',
		'化妆品',
		'食品',
		'日用品',
		'其他',
	]
	const active = ref()
	
	const onChange = (value) => {
		packageInfo.value.weight = value
	}
	const onClick = (index) => {
		active.value = index
		packageInfo.value.itemName = list[index]
	}
	const onConfirm = () => {
		if (!packageInfo.value.itemName) {
			uni.showToast({
			  title: '请选择物品类型',
			  icon: 'none',
			});
			return
		}
		if (!packageInfo.value.weight) {
			uni.showToast({
			  title: '请输入预估重量',
			  icon: 'none',
			});
			return
		}
		store.setPackageInfo(packageInfo.value)
		sheep.$router.back()
	}
	
	onShow(() => {
		packageInfo.value = {
			...store.packageInfo
		}
		active.value = list.findIndex(e => e == store.packageInfo.itemName)
	})
</script>

<style lang="scss" scoped>
	.container {
		width: 95%;
		margin: 0 auto;
		padding-bottom: 148rpx;
	}
	.title {
		font-size: 32rpx;
		font-weight: 600;
		color: #000000;
	}
	.red {
		font-size: 24rpx;
		color: red;
	}
	.type-box {
		.list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			row-gap: 40rpx;
			.item {
				width: 160rpx;
				height: 64rpx;
				line-height: 64rpx;
				text-align: center;
				color: #101010;
				border: 2rpx solid #eeeeee;
				border-radius: 64rpx;
				&.active {
					background-color: #0396ff;
					color: #fff;
				}
			}
		}
		.current {
			display: flex;
			align-items: center;
			height: 64rpx;
			border-radius: 64rpx;
			padding: 0 20rpx;
			border: 2rpx solid #eeeeee;
			color: #000000;
			font-size: 32rpx;
			margin: 40rpx 0;
		}
	}
	.measure-box {
		.size {
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			color: #000000;
			border: 2rpx solid #eeeeee;
			.label {
				width: 110rpx;
				background-color: #eeeeee;
			}
			input {
				flex: 1;
			}
		}
	}
	.tip-box {
		font-size: 24rpx;
		color: #989898;
		line-height: 40rpx;
	}
	.textarea {
		width: auto;
		border: 2rpx solid #eeeeee;
		border-radius: 10rpx;
		color: #000000;
		height: 200rpx;
		padding: 10rpx;
	}
	.fixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		padding: 30rpx;
		background-color: #fff;
		box-sizing: border-box;
		z-index: 99;
		.button {
			height: 88rpx;
			line-height: 88rpx;
			font-size: 36rpx;
			color: #fff;
			border-radius: 88rpx;
			background-color: #0396ff;
			outline: none;
			border: none;
		}
	}
</style>